package com.smasher.update.executor

import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit

class LoongExecutor private constructor(
    corePoolSize: Int,
    maximumPoolSize: Int,
    keepAliveTime: Long,
    unit: TimeUnit,
    workQueue: LinkedBlockingQueue<Runnable>
) : ThreadPoolExecutor(
    corePoolSize,
    maximumPoolSize,
    keepAliveTime,
    unit,
    workQueue
) {


    private object SingletonHolder {
        val holder = LoongExecutor(
            CORE_POOL_SIZE,
            MAX_POOL_SIZE,
            KEEP_ALIVE_TIME,
            TimeUnit.MILLISECONDS,
            LinkedBlockingQueue<Runnable>()
        )
    }

    companion object {
        private const val CORE_POOL_SIZE = 1
        private const val MAX_POOL_SIZE = 1
        private const val KEEP_ALIVE_TIME = 0L

        @JvmStatic
        fun getInstance(): LoongExecutor {
            return SingletonHolder.holder
        }
    }
}